# 一、封装
# self的作用  self 是指向对应的中间人成为指向指针
#
# class Person:
#
#     def __init__(self,name,age):
#         self.name = name
#         self.age = age
#         self.sex = "男"
#
#     def show(self,action):
#         self.action = action
#         print(self.name,self.age,self.sex,self.action)
#
# a = Person("姚亚光",18)
# a.show(action="play")
#
# b = Person("王菲",90)
# b.show(action='dance')
#
# 可以将公共的属性封装到构造函数中
# 如果某个公共属性都是一样的话，可以直接self.sex = "男"来定义
#
# 二、继承
#
# class Father:
#
#     def lanqiu(self):
#         print("喜欢篮球")
#
#     def zuqiu(self):
#         print("喜欢足球")
#
# class Son(Father):
#
#     def dabaojian(self):
#         print("喜欢大保健")
#
# a = Son()
# a.lanqiu()
#
#
#
# 类名括号里面加其他类名 用来继承 ，如果子类里的方法名和父类一致，那就是重写了子类，使用子类中的方法
#
# class Father:
#
#     def lanqiu(self):
#         print("喜欢篮球")
#
#     def zuqiu(self):
#         print("喜欢足球")
#
# class Son(Father):
#
#     def dabaojian(self):
#         super(Son,self.lanqiu())
#         print("喜欢大保健")
#
# a = Son()
# a.dabaojian()
#
#
#
# 在子类中使用super可以即调用父类的方法，也调用子类的方法
#
# 多继承，依次从左边开始找父类，如果多个父类有同一个基类，先找完父类，最后再找基类
#
# 在类中的字段称为静态字段
#
#
#
# 静态方法，可以在类中直接调用，无需创建对象
#
# class Person:
#
#     @staticmethod
#     def test():
#         print(123)
#
# Person.test()
#
#
#
# 使用property可以像调用属性一样调用方法class Person:
#
#     @property
#     def test(self):
#         print("123")
#
#
#
# 类的静态方法
#
# obj = Person()
# obj.test
# class Person:
#
#     @property
#     def test(self):
#         print("123")
#
#     @test.setter
#     def set(self,value):
#         print(value)
#
#     @test.deleter
#     def delete(self):
#         print("删除")
#
#
# obj = Person()
# obj.test
# obj.set= 666
# del obj.delete
#
#
#
#
# 在类中，属性名前加两个下划线__可以限制外部访问
# 例(限制外部访问后，进行访问类中的属性)：
# class Student(object):
#
#     def __init__(self,name,score):
#         self.__name = name
#         self.__score = score
#
#     def print_score(self):
#         print('%s: %s' %(self.__name,self.__score))
#
#     def get_name(self):
#         return self.__name
#
#     def get_score(self):
#         return self.__score
#
#     def set_score(self):
#         if 0<= self.__score <= 100:
#             return self.__score
#         else:
#             raise ValueError('bad score')
#
#
# bart = Student('yao',60)
# print(bart.get_name(),bart.get_score())
# bart = Student('li',-1)
# print(bart.set_score())
#
#
# 特殊成员
# __call__通过obj()可以直接调用
# class Person:
#
#    def __call__(self, *args, **kwargs):
#        print('123')
#
# obj = Person()
# obj()
#
#
# 用过__int__  __str__来转换对象obj的类型
# class Person:
#
#    def __int__(self):
#        return 123
#
#    def __str__(self):
#        return "hello"
#
# obj = Person()
# r = int(obj)
# print(r)
# y = str(obj)
# print(y)
#
#
# __add__两个对象相加，相加的结果可以自己随便写
# class Person:
#
#    def __init__(self,name,age):
#        self.name = name
#        self.age = age
#
#    def __add__(self, other):
#        return "我是obj3"
#
# obj1 = Person("alex",19)
# obj2 = Person("yao",20)
# r = obj1 + obj2
# print(r)
#
#
# __dict__返回一个字典，显示所有成员
# class Person:
#
#    def __init__(self,name,age):
#        self.name = name
#        self.age = age
#
# obj = Person("alex",19)
# print(obj.__dict__)
#
#
# 通过列表来获取、设置、删除值
# class Person:
#
#    def __init__(self,name,age):
#        self.name = name
#        self.age = age
#
#    def __getitem__(self, item):
#        return 123
#
#    def __setitem__(self, key, value):
#        print(key,value)
#
#    def __delitem__(self, key):
#        print(999)
#
# obj = Person("alex",19)
# print(obj[0])
# obj[1] = 789
# del obj[888]
#
#
# __iter__方法进行迭代
# class Person:
#
#    def __init__(self,name,age):
#        self.name = name
#        self.age = age
#
#    def __iter__(self):
#        return iter([1,2,3,4,5])
#
# obj = Person("alex",19)
# for i in obj:
#     print(i)
#
#
# getattr setattr delattr 直接获取方法无需创建对象
# 用法示例：
# 文件s1
#
# 文件2
#
# import s1
#
# r = input("输入您要查看的页面:")
# if hasattr(s1,r):
#     r = getattr(s1,r)
#     r()
# else:
#     print("404")


